/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.nodes.sprites;

import com.android1.amarena2d.animation.Animation;
import com.android1.amarena2d.engine.GL;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.behavior.delegates.AnimatedActionTarget;
import com.android1.amarena2d.texture.ManagedTexture;
import com.android1.amarena2d.texture.TextureFrame;
import com.android1.amarena2d.texture.TexturedMesh;

/**
 * Has its own TexturedMesh and will save position in mesh.
 * Faster then Sprite due to no gl.translate, but updating the position is more expensive.
 * Should only be used for entities with a fix position.
 */
public class StaticSprite extends Sprite implements AnimatedActionTarget.SetFrame {


    public StaticSprite(TexturedMesh texturedMesh) {
        super(texturedMesh);
    }

    public StaticSprite(TextureFrame textureFrame) {
        super(textureFrame);
    }

    public StaticSprite(TextureFrame textureFrame, float x, float y) {
        super(textureFrame, x, y);
    }

    public StaticSprite(ManagedTexture managedTexture) {
        super(managedTexture);
    }

    public StaticSprite(ManagedTexture managedTexture, float x, float y) {
        super(managedTexture, x, y);
    }

    public StaticSprite(String texturePath) {
        super(texturePath);
    }

    public StaticSprite(String texturePath, float x, float y) {
        super(texturePath, x, y);
    }

    public StaticSprite(Animation animation) {
        super(animation);
    }

    public StaticSprite(Animation animation, float x, float y) {
        super(animation, x, y);
    }

    @Override
    public void render() {
        if (!init || !active || !visible)
            return;

        if (Scene.CULLING && !this.disableCulling && !this.isVisibleOnScreen())
            return;

        final boolean isTranslate = transformDelegate != null;

        if (isTranslate)
            GL.pushMatrix();

        GL.setColor(this.color);

        if (transformDelegate != null) {
            transformDelegate.apply();
        }
        GL.blendFunc(blendFunction);
        texturedMesh.render();

        if (isTranslate)
            GL.popMatrix();

    }

    @Override
    public void setXY(float x, float y) {
        super.setXY(x, y);
        texturedMesh.setXY(getX(), getY());
    }

    @Override
    public void setX(float x) {
        super.setX(x);
        texturedMesh.setX(getX());
    }

    @Override
    public void setY(float y) {
        super.setY(y);
        texturedMesh.setY(getY());
    }

    @Override
    public void setAbsoluteY(float y) {
        //todo
        super.setAbsoluteY(y);
    }

    @Override
    public void setAbsoluteX(float x) {
        //todo
        super.setAbsoluteX(x);
    }
}
